﻿using System;

/*
 *  author: able
 *  @2012/2/21 16:49:50
 * 
 */
namespace __ts.Core.Util
{
    public class Assert
    {
        /**
         * Returns <code>value</code> if it is not <code>null</code>. Otherwise a
         * {@link IllegalArgumentException} will be thrown, the given
         * <code>parameterName</code> is included in the Message. Eg. <br>
         * <br>
         * <b>Example:</b>
         * If <code>null</code> will be passed, the message of the exception is <i>"Parameter >value< must not be null !"</i>
         * <pre>
         * public void myMethod(Integer value){
         *     <b>assertNotNull(value,"value");</b>
         *     ...
         * }
         * </pre>
         * @param <T>
         *            Type of the value
         * @param value
         *            the value to check
         * @param parameterName
         *            name of the parameter to be included in a possible
         *            {@link IllegalArgumentException}
         * @return parameter <code>value</code>
         * @exception IllegalArgumentException if <code>value==null</code>
         */
        public static T assertNotNull<T>(T value, String parameterName)
        {
            if (parameterName == null)
            {
                throw new ArgumentException("You must provide a parameter name!");
            }
            if (value == null)
            {
                throw new ArgumentException("Parameter >" + parameterName + "< must not be null!");
            }
            return value;
        }
    }
}